def fun1():
    # 输入摄氏度，转换为华氏度
    celsius = float(input("请输入摄氏度: "))
    fahrenheit = (celsius * 1.8) + 32
    print(f"{celsius} 摄氏度 = {fahrenheit} 华氏度")

    # 输入华氏度，转换为摄氏度
    fahrenheit = float(input("请输入华氏度: "))
    celsius = (fahrenheit - 32) / 1.8
    print(f"{fahrenheit} 华氏度 = {celsius} 摄氏度")

def fun2():
    year = int(input("请输入年份: "))

    if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
        print(f"{year} 是闰年")
    else:
        print(f"{year} 不是闰年")


def fun3():
    n = int(input("请输入数列长度: "))
    a, b = 0, 1

    for i in range(n):
        print(a, end=" ")
        a, b = b, a + b




def fun5():
    text = "hello world hello python world python"
    words = text.split()
    word_count = {}

    for word in words:
        word_count[word] = word_count.get(word, 0) + 1

    print("单词频率:", word_count)


def fun6():
    file_path = "example.txt"

    with open(file_path, "r") as file:
        lines = file.readlines()
        line_count = len(lines)
        word_count = sum(len(line.split()) for line in lines)

    print(f"文件共有 {line_count} 行，{word_count} 个单词")


def fun7():
    import random

    file_path = "random_numbers.txt"

    with open(file_path, "w") as file:
        for _ in range(100):
            file.write(f"{random.randint(1, 100)}\n")

    print("随机数已写入文件")

class FunDemo:
    def fun4(self):
        # 排序和反转
        numbers = [3, 1, 4, 1, 5, 9, 2, 6]
        sorted_numbers = sorted(numbers)  # 排序
        reversed_numbers = numbers[::-1]  # 反转

        print("原始列表:", numbers)
        print("排序后:", sorted_numbers)
        print("反转后:", reversed_numbers)

        # 去重（保持顺序）
        unique_numbers = []
        for num in numbers:
            if num not in unique_numbers:
                unique_numbers.append(num)
        print("去重后:", unique_numbers)
        set_numbers = list(set(numbers))
        print("去重后(使用集合):", set_numbers)

if __name__ == "__main__":
    fun7()

